<?php

namespace App\Http\Controllers;

use App\Banner;
use App\Services\AutoService;
use App\Services\UserService;
use Illuminate\Http\Request;

/**
 * 首页显示数据
 * Class IndexController
 * @package App\Http\Controllers
 */
class IndexController extends BaseController
{
    /**
     * 首页数据
     */
    public function index(Request $request){
        $this->uid = \session('uid')??0;
//        banenr列表
        $banner = Banner::where('type', 1)->where('status', 1)->get();
//        广告1
        $banner1 = Banner::where('type', 2)->where('status', 1)->first();
//        会员广告
        $banner2 = Banner::where('type', 3)->where('status', 1)->first();
        if( $this->uid ){
            //写入访问日志
            if( !\DB::table('users_use_log')->where("uid", $this->uid)->whereDate('created_at', date('Y-m-d'))->count() ){
                \DB::table('users_use_log')->insert(["uid"=>$this->uid, "created_at"=>\getDt()]);
            }
        }
        
        return returnJson(0, "", ['banner'=>$banner, 'banner1'=>$banner1, 'banner2'=>$banner2]);
    }

    public function test(){
//        $imgs = explode(',', 'public\\orderImg\\10009\\c8b8c36ed8e80d180d66fc5143afba2a.jpeg,public\\orderImg\\10009\\20210430104759.jpg');
//        $arr = [];
//        if( is_array($imgs) && count($imgs) ){
//            foreach ($imgs as $img) {
//                $resultWords = imgRecognition(base_path($img));
//                if( $resultWords ){
//                    $arr = array_merge($arr, $resultWords);
//                }
//            }
//        }
//        $result = autoAudit($arr, '111885590667582273', '蔡大胖炸洋芋(少陵路店)', '19.45', '2021-04-24');
//        var_dump($result);
//        AutoService::orderAudit();
        // AutoService::orderNotSettleNotify();
        // AutoService::notSettleCheck();
    }
}
